package com.nithya.hms;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class AuthIntercepter extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		HttpSession session = request.getSession();
		Doctor doctor = (Doctor) session.getAttribute("doctor");
		Patient patient = (Patient) session.getAttribute("patient");
		if(doctor == null && patient ==null){
			String redirectURL = request.getContextPath() + "/index.do";
			response.sendRedirect(redirectURL);
		}
		return true;
	}

}